package com.supertimetable.bean;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;


import com.supertimetable.activities.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Admin on 2018/1/10.
 */

public class ScheduleTable extends Fragment {
    private TextView textView;
    private GridView grid;
//    private String[] texts = new String[]{
//            "1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28"
//    };
    private String[] []  ts= new String[6][8];


    private String[] texts = new String[50];
    int sum = 1 ;
    public void init(){
        for(int i =0; i < 6; i++ ){
            for(int j = 0; j <  8;j++){
                if (j%8==0){
                    ts[i][j] = sum+"";
                    sum++;
                }else{
                ts[i][j] = "语文语文语文语文语文"+i+"-"+j;}
            }
        }
        int index = 0;
        for(int i =0; i < 6; i++ ){
            for(int j = 0; j <  8;j++){
                texts[index] = ts[i][j];
                index++;
            }
        }
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View view = inflater.inflate(R.layout.activity_list,container,false);
        /*List<Map<String,Object>> listItem = new ArrayList<Map<String,Object>>();
        for (int i=0;i<course.length;i++){
            Map(String,Object) listItem = (List<Map<String, Object>>) new HashMap<String,Object>();
        }*/
        List<Map<String,Object>> listItems = new ArrayList<Map<String,Object>>();
//        for(int i = 0 ; i<texts.length;i++){
//
//            Map<String,Object> listItem = new HashMap<String,Object>();
//            listItem.put("text",texts[i]);
//            listItems.add(listItem);
//
//        }

        init();
        for(int i = 0 ; i<texts.length;i++){

            Map<String,Object> listItem = new HashMap<String,Object>();
            listItem.put("text",texts[i]);
            listItems.add(listItem);

        }
        textView = (TextView) view.findViewById(R.id.textView);
//        findViewById(R.id.grid01);
        SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(),listItems,R.layout.cell,new String[]{"text"},new int[]{R.id.text1});


        grid = (GridView) view.findViewById(R.id.grid01);


        grid.setAdapter(simpleAdapter);
        grid.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                textView.setText(texts[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
        grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                textView.setText(texts[position]);
            }
        });


        return view;
    }

}
